const express = require('express')
const router = express.Router()

const sysUserController = require('../controller/SysUserController')

/**
 * @api {get} /api/v1/user/list 获取用户列表
 * @apiDescription /api/v1/user/list
 * @apiName list
 * @apiGroup SysUser
 * @apiBody {number} [userId]      用户id
 * @apiBody {number} [deptId]         部门id
 * @apiBody {string} [loginName]      登录名
 * @apiBody {string} [userName]       用户名
 * @apiBody {string} [userType]       用户类型
 * @apiBody {string} [email]          邮箱
 * @apiBody {string} [avatar]         头像
 * @apiBody {string} [phoneNumber]    手机号
 * @apiBody {string} [password]       密码
 * @apiBody {string} [sex]            性别
 * @apiBody {number} [status]         状态
 * @apiBody {string} [remark]         备注
 * @apiBody {date} [createAt]       创建时间
 * @apiSampleRequest /api/v1/user/list
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysUser[]} data 用户信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 200 OK
 *  {
 *      "code" : 200,
 *      "data" : [
 *        {
            "userId": 1,
            "deptId": 103,
            "loginName": "admin",
            "userName": "kuake",
            "userType": "00",
            "email": "ry@163.com",
            "avatar": "",
            "phoneNumber": "15888888888",
            "password": "56963f91d151bcec486202ddfe961e1b",
            "sex": "1",
            "salt": "111111",
            "status": "0",
            "delFlag": "0",
            "lastLoginIp": "127.0.0.1",
            "lastLoginDate": "2023-08-23T17:16:22.000Z",
            "createdBy": "admin",
            "createAt": "2023-08-23T17:16:22.000Z",
            "remark": "管理员",
            "deptName": "研发部门",
            "leader": "kuake"
 *        }
 *      ],
 *      "message" : "请求成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/list', sysUserController.userList)


/**
 * @api {get} /api/v1/user/:id 根据id查询用户信息
 * @apiDescription /api/v1/user/:id
 * @apiName getUserById
 * @apiGroup SysUser
 * @apiParam {number} id 用户id
 * @apiSampleRequest /api/v1/user/:id
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysUser} data 用户信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" :  {
            "userId": 1,
            "deptId": 103,
            "loginName": "admin",
            "userName": "kuake",
            "userType": "00",
            "email": "ry@163.com",
            "avatar": "",
            "phoneNumber": "15888888888",
            "password": "56963f91d151bcec486202ddfe961e1b",
            "sex": "1",
            "salt": "111111",
            "status": "0",
            "delFlag": "0",
            "lastLoginIp": "127.0.0.1",
            "lastLoginDate": "2023-08-23T17:16:22.000Z",
            "createdBy": "admin",
            "createAt": "2023-08-23T17:16:22.000Z",
            "remark": "管理员",
            "deptName": "研发部门",
            "leader": "kuake"
 *        },
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.get('/:id', sysUserController.selectUserById)


/**
 * @api {post} /api/v1/user/add 添加用户
 * @apiDescription /api/v1/user/add
 * @apiName add
 * @apiGroup SysUser
 * @apiBody {number} [deptId]      部门id
 * @apiBody {string} loginName   登录名
 * @apiBody {string} userName    用户名
 * @apiBody {string} userType    用户类型
 * @apiBody {string} email        邮箱
 * @apiBody {string} [avatar]       头像
 * @apiBody {string} phoneNumber 手机号
 * @apiBody {string} password       密码
 * @apiBody {string} sex            性别
 * @apiBody {number} status         状态
 * @apiBody {string} remark         备注
 * @apiSampleRequest /api/v1/user/add
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysUser[]} data 用户信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 201 OK
 *  {
 *      "code" : 201,
 *      "data" : true,
 *      "message" : "添加用户成功",
 *  }
 * @apiVersion v1.0.0
 */
router.post('/add', sysUserController.addUser)


/**
 * @api {put} /api/v1/user/update 修改用户
 * @apiDescription /api/v1/user/update
 * @apiName update
 * @apiGroup SysUser
 * @apiBody {number} userId      用户id
 * @apiBody {number} [deptId]    部门id
 * @apiBody {string} loginName   登录名
 * @apiBody {string} userName    用户名
 * @apiBody {string} userType    用户类型
 * @apiBody {string} email        邮箱
 * @apiBody {string} [avatar]       头像
 * @apiBody {string} phoneNumber 手机号
 * @apiBody {string} password       密码
 * @apiBody {string} sex            性别
 * @apiBody {number} status         状态
 * @apiBody {string} remark         备注
 * @apiSampleRequest /api/v1/user/update
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysUser[]} data 用户信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 208 OK
 *  {
 *      "code" : 208,
 *      "data" : true,
 *      "message" : "修改成功",
 *  }
 * @apiVersion v1.0.0
 */
router.put('/update', sysUserController.updateUser)


/**
 * @api {delete} /api/v1/user/delete 删除用户
 * @apiDescription /api/v1/user/delete
 * @apiName delete
 * @apiGroup SysUser
 * @apiBody {number} id 用户id
 * @apiSampleRequest /api/v1/user/delete
 * @apiSuccess {number} code 响应状态码
 * @apiSuccess {SysUser[]} data 用户信息
 * @apiSuccessExample {json} Success-Response:
 *  HTTP/1.1 204 OK
 *  {
 *      "code" : 204,
 *      "data" : true,
 *      "message" : "删除成功",
 *  }
 * @apiVersion v1.0.0
 */
router.delete('/delete', sysUserController.deleteUser)

module.exports = router